import JSEncrypt from "jsencrypt/bin/jsencrypt.min"
import CryptoJS  from 'crypto-js' 
const publicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyUUmpjvMiiU8mL3gvqXq\n' +
'cTPylF6aYNL+FfiBaz6byOBuNp4/2A6MNqzMadrmsCw3PJaR7jQIq3OGltZYtyPI\n' +
'QOpSgSv5/EuhDDQzIFM8IB3d67i2hYUHn2lwrpEvtvchdY+dGmkqnW1rE8JF1YhZ\n' +
'+TNw7LtbTfkH+dUx5cHXxoC+sA6RmXnwjtPmluxUnnMK21l/lybHtPpMAipJok7V\n' +
'p8ZgebOnb+fymDsZ/SeBg0iKgFLB/fITISxwn9HG1h1Jzn2AbLuhWd1sfnSYoBPj\n' +
'2ECiVVeKEdP29HuhNuD8Zo9u25NSvJlg1i5ypYmN+SjDk/2bkl+KszUvZzqEbZh1\n' +
'FwIDAQAB'


const aesPrivateKey = 'uUS#N6okHJqsh0BB'
// 加密
export const encrypt = (txt) => {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt)
}

// aes加密
export function aesEncrypt(txt) {
  const key = CryptoJS.enc.Utf8.parse(aesPrivateKey);
  const iv = CryptoJS.lib.WordArray.create(CryptoJS.enc.Utf8.parse(aesPrivateKey));
  const encrypted = CryptoJS.AES.encrypt(txt, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  });
  return encrypted.toString();
}